#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <sys/time.h>
#include <iostream>
#include <unistd.h>
#include <pthread.h>

#include "fillArgument.h"
#include "Computation.h"

#define B 1
#define KB 1024
#define MB 1048576

using namespace std;
using namespace CommandLineProcessing; 

int main(int argc, char * argv[]){

  // Environement
  Environment * env = new Environment(); 
  Computation * test = NULL; 
  // Parser for argument. 
  ArgvParser parser; 
  fillArguments(&parser);

  // parse and handle return codes (display help etc...)
  int result = parser.parse(argc, argv);
  if (result != ArgvParser::NoParserError){
    cout << parser.parseErrorDescription(result);
    exit(1);
  }

  // use parser to create the tests environment
  // define size 
  if(parser.foundOption("o")) {
    env->setOperation(parser.optionValue("o")); 
  }else {
    env->setMaxOperation();
  }

  // define thread
  if(parser.foundOption("t")){
    env->setThread(parser.optionValue("t"));
  }else {
    env->setThread("4");
  }

  // define access 
  if (parser.foundOption("c")){
    env->setComputation(parser.optionValue("c"));
  }else {
    env->setComputation(0);
  }  
  //Run the benchMark using the parameters saved in the environment
  test = new Computation(env);
  test->runTests();

  delete test;
}
